package com.gsafety.libraryktx.expand

import android.widget.CheckBox
import android.widget.CompoundButton
import com.gsafety.library.Exts.Ext
import com.gsafety.library.common.OnBlockCheckedChangeListener

/**
 *
 * @param checked  选中状态
 * @param useBlock 是否响应改变回调
 */
inline fun <reified T : CheckBox> T.setChecked(checked: Boolean, useBlock: Boolean = false)
{
    Ext.setChecked(this, checked, useBlock)
}

/**
 * 设置有条件的响应选中事件
 */
inline fun <reified T : CheckBox> T.setOnCheckedChange(crossinline block: (view: T, isChecked: Boolean) -> Unit)
{
    Ext.setOnCheckedChange(this, object : OnBlockCheckedChangeListener()
    {
        override fun onChanged(buttonView: CompoundButton, isChecked: Boolean)
        {
            if (buttonView is T)
            {
                block.invoke(buttonView, isChecked)
            }
        }
    })
}